export function getDeviceId(): string {
  // 生成或获取设备唯一标识
  const key = 'uni_error_sdk_device_id';
  
  try {
    let deviceId = uni.getStorageSync(key);
    if (!deviceId) {
      deviceId = generateUUID();
      uni.setStorageSync(key, deviceId);
    }
    return deviceId;
  } catch {
    return generateUUID();
  }
}

function generateUUID(): string {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
    const r = Math.random() * 16 | 0;
    const v = c === 'x' ? r : (r & 0x3 | 0x8);
    return v.toString(16);
  });
}